package com.zhuangxiaoyan.designpattern.singletonmodel;

public class SingletonDemo2 {

    private SingletonDemo2() {
    }

    /**
     * 使用volatile 关键字+双重锁机制
     */
    private static volatile SingletonDemo2 singletonDemo2;

    public static SingletonDemo2 getInstance() {
        if (singletonDemo2 == null) {
            synchronized (singletonDemo2.getClass()) {
                if (singletonDemo2 == null) {
                    singletonDemo2 = new SingletonDemo2();
                }
            }
        }
        return singletonDemo2;
    }
}
